home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 466_01 / SRC / FMTPARA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-20  |  5.6 KB  |  284 lines

  1. #include <afx.h>
  2. #include <afxtempl.h>
  3. #include "parse.h"
  4. #include "topiclog.h"
  5. #include "input.h"
  6. #include "fmt.h"
  7. #include "fmtif.h"
  8. #include "fmttag.h"
  9. #include "fmtPara.h"
  10. #include "errmsg.h"
  11.  
  12.  
  13. /******************************************************/
  14. // Tag list
  15. /******************************************************/
  16.  
  17. TAGSPEC gtagsParaSection[] =
  18. {
  19.     CFmtListPara::tagTag,              "tag",
  20.     CFmtListPara::tagPre,            "pre",
  21.     CFmtListPara::tagFormat,        "format",
  22.     CFmtListPara::tagPost,           "post",
  23.     CFmtListPara::tagIf,              "if",
  24.     CFmtListPara::tagSrcParse,         "parsesource",
  25.     CFmtListPara::tagSrcParse,         "parse",
  26.     CFmtListPara::tagMap,            "map",
  27.     -1,        NULL,
  28. };
  29.  
  30.  
  31. static TAGSPEC PARSETYPES[] = 
  32. {
  33.     CFmtPara::parseMember,         "classmember",
  34.     CFmtPara::parseField,        "field",
  35.     CFmtPara::parseParam,         "parameter",
  36.     CFmtPara::parseParamOpt,    "parameteropt",
  37.     CFmtPara::parseEmem,        "emem",
  38.     CFmtPara::parseBparam,        "bparameter",
  39.     CFmtPara::parseBfield,        "bfield",
  40.     CFmtPara::parseMeth,        "method",
  41.     CFmtPara::parseFriend,      "friend",
  42.     -1,             NULL,
  43. };
  44.  
  45.  
  46. /******************************************************/
  47. // Map class
  48. /******************************************************/
  49.  
  50. CMapPara::CMapPara(void)
  51. {
  52.     InitName(m_name, MAXNUMFIELDS);
  53. }
  54.  
  55.  
  56. /******************************************************/
  57. // Format class
  58. /******************************************************/
  59.  
  60. CFmtPara::CFmtPara(void) : CFmtTag(3)
  61. {
  62.     m_nLevel = 0;
  63.     m_nParseType = 0;
  64.     m_nFlags.isExample = FALSE;
  65. }
  66.  
  67. CFmtPara::~CFmtPara(void)
  68. {
  69.     POSITION pos = m_mapPara.GetHeadPosition();
  70.     CMapPara *p;
  71.  
  72.     while( pos != NULL )
  73.     {
  74.         p = m_mapPara.GetNext(pos);
  75.         delete p;
  76.     }
  77. }
  78.  
  79. NAMETOKEN *CFmtPara::GetMap(const char *szTag)
  80. {
  81.     CMapPara *pmap;
  82.     POSITION pos = m_mapPara.GetHeadPosition();
  83.  
  84.     while( pos != NULL )
  85.     {
  86.         pmap = m_mapPara.GetNext(pos);
  87.         if(_stricmp(pmap->m_sName, szTag) == 0)
  88.             return pmap->m_name;
  89.     }
  90.  
  91.     return NULL;
  92. }
  93.  
  94.  
  95.  
  96.  
  97. #ifdef _DEBUG
  98. void CFmtPara::Dump(CDumpContext &dc) const
  99. {
  100.     CFmtTag::Dump(dc);
  101.  
  102.     dc << "\tlevel: "<< m_nLevel << "; example=";
  103.     if(m_nFlags.isExample)
  104.         dc << "yes";
  105.     else
  106.         dc << "no";
  107.     dc << "; parse: ";
  108.     
  109.     for(int i = 0; PARSETYPES[i].iTag != -1 && PARSETYPES[i].iTag != m_nParseType; i++);
  110.     
  111.     dc << PARSETYPES[i].szName << "\r\n";
  112. }
  113. #endif
  114.  
  115. /******************************************************/
  116. // List class
  117. /******************************************************/
  118.  
  119.  
  120. TAGSPEC *CFmtListPara::FmtTagList(void)
  121. {
  122.     return gtagsParaSection;
  123. }
  124.     
  125.  
  126. int CFmtListPara::ParseEntry(CFmtInput &in)
  127. {
  128.     int nRet;
  129.     const char *sz1;
  130.  
  131.     CFmtPara *pNew;
  132.  
  133.     pNew = (CFmtPara *)m_pNew;
  134.  
  135.     switch(m_nTag)
  136.     {
  137.     // Parent
  138.  
  139.     case tagTag:
  140.         
  141.         // Expect: .tag = name, output, fields, sortweight, nametemplate
  142.  
  143.         if(in.m_nTokens != 4 && in.m_nTokens != 5)
  144.             return fmterrBadEntryCount;
  145.  
  146.         if(!CheckOutputType(in, 1))
  147.             return 0;
  148.  
  149.         nRet = CheckAddTag();
  150.         if(nRet)
  151.             return nRet;
  152.  
  153.         // Make a new one
  154.  
  155.         m_pNew = pNew = new CFmtPara;
  156.  
  157.         m_nState.Tag = TRUE;
  158.  
  159.         // Record source file information.
  160.  
  161.         pNew->SetSource(in.m_nFile, in.m_lCurLine);
  162.  
  163.         // Get the required Name field.
  164.         
  165.         nRet = ParseName(pNew->m_sName, in.m_aszTokens[0]);
  166.         if(nRet)
  167.             return nRet;        
  168.  
  169.         // Get the required number of fields
  170.         
  171.         nRet = ParseNumFields(pNew->m_nNumFields, in.m_aszTokens[2]);
  172.         if(nRet)
  173.             return nRet;
  174.         
  175.         // Get the required level
  176.         
  177.         sz1 = EatWhite(in.m_aszTokens[3]);
  178.         if(!isdigit(*sz1))
  179.             return fmterrParaExpectedLevel;
  180.             
  181.         MakeNumber(sz1, pNew->m_nLevel);
  182.         
  183.         // Example tag flag 
  184.         
  185.         if(in.m_nTokens == 5)
  186.         {
  187.             sz1 = EatWhite(in.m_aszTokens[4]);
  188.             switch(*sz1)
  189.             {
  190.             case '0':
  191.                 pNew->m_nFlags.isExample = FALSE;
  192.                 break;
  193.  
  194.             case '1':
  195.                 pNew->m_nFlags.isExample = TRUE;
  196.                 break;
  197.  
  198.             default:
  199.                 return fmterrParaExpectedExFlag;
  200.             }
  201.         }
  202.  
  203.         break;
  204.  
  205.     case tagSrcParse:                    // Get the parsing type
  206.  
  207.         nRet = ParseSrcParse(pNew->m_nParseType, in, PARSETYPES);
  208.         if(nRet)
  209.             return nRet;
  210.         
  211.         break;
  212.     
  213.     case tagIf:
  214.         
  215.         nRet = ParseIf(*pNew, in);
  216.         if(nRet)
  217.            return nRet;
  218.  
  219.         break;
  220.  
  221.     case tagMap:
  222.     {
  223.         // Validate entry.
  224.  
  225.         if(m_nState.Skip)
  226.             return 0;
  227.  
  228.         if(!m_nState.Tag)
  229.             return fmterrOrphanedTag;
  230.  
  231.         if(in.m_nTokens < 2 || in.m_nTokens > MAXNUMFIELDS+1)
  232.             return fmterrBadEntryCount;
  233.  
  234.         // Make a map.
  235.         CMapPara *pmap = new CMapPara;
  236.  
  237.         // Get the required Name field.
  238.         
  239.         nRet = ParseName(pmap->m_sName, in.m_aszTokens[0]);
  240.         if(nRet)
  241.             return nRet;
  242.         
  243.         // Get the name mapping
  244.  
  245.         int i,j;
  246.         const char *sz;
  247.         for(i = 1, j = 0; i < in.m_nTokens; i++, j++)
  248.         {
  249.             sz = EatWhite(in.m_aszTokens[i]);
  250.             if(chDollar != *sz)
  251.                 return fmterrBadMapFieldReference;
  252.  
  253.             sz++;
  254.             nRet = ParseNameToken(sz, &pmap->m_name[j], pNew->m_nNumFields);
  255.             if(nRet)
  256.                 return nRet;
  257.         }
  258.  
  259.         pNew->m_mapPara.AddTail(pmap);
  260.  
  261.         break;
  262.     }
  263.  
  264.     // RTF file header and footer
  265.  
  266.     case tagPre:
  267.     case tagPost:
  268.     case tagFormat:
  269.  
  270.         // expect: .pre= format string
  271.  
  272.         nRet = SetFmtString(in, 0);
  273.  
  274.         if(nRet)
  275.             return nRet;
  276.         break;
  277.  
  278.     default:
  279.         return fmterrBadFmtEntry;
  280.     }
  281.  
  282.     return 0;
  283. }
  284.